package _01_动态数组;

import java.util.HashSet;
import java.util.Set;

public class _575_分糖果 {

    public int distributeCandies(int[] candyType) {
        boolean[] container = new boolean[200001];
        int half = candyType.length >> 1;
        int total = 0;
        for (int i : candyType) {
            if (total >= half) break;
            if (!container[i + 100000]) {
                total++;
                container[i + 100000] = true;
            }
        }
        return total;
    }

    public int distributeCandies1(int[] candyType) {
        Set<Integer> map = new HashSet<>();
        for (int i : candyType) {
            map.add(i);
        }
        return Math.min(map.size(), candyType.length >> 1);
    }

}
